package abstractfactory.dao;

public class DataAccess {

    private static final String db = "com.cqupt.demo.design_pattern" +
            ".abstractfactory.dao.SqlServer";

    public static IUser createUser() {
        String className = db + "user";
        IUser user = null;
        try {
            user = (IUser) Class.forName(className).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return user;
    }

    public static IDepartment createDepartment() {
        String className = db + "Department";
        IDepartment department = null;
        try {
            department = (IDepartment) Class.forName(className).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return department;
    }
}
